<?php

class Mailer {

    public $title;
    public $msg;
    public $emailAddressTo;

    private $host = 'smtp.163.com';
    private $port = 25;
    private $emailAddressFrom = 'support@maptopro.com';
    private $emailPwdFrom = 'qqsv1\/2sv\?';
    private $fromEmail = 'support@maptopro.com';
    private $fromName = 'maptopro';

    public function __construct($title, $msg, $emailAddressTo) {

        $this->title = $title;
        $this->msg = $msg;
        $this->emailAddressTo = $emailAddressTo;
    }

    /**
     * @return bool
     */
    public function send() {

        $mailer = Yii::app()->mailer;
        $mailer->Host = $this->host;
        $mailer->Port = $this->port;

        $mailer->SMTPDebug = false;
        $mailer->IsSMTP();
        $mailer->SMTPAuth = true;
        $mailer->CharSet = 'UTF-8';

        $mailer->Username = $this->emailAddressFrom;
        $mailer->Password = $this->emailPwdFrom;

        $mailer->From = $this->fromEmail;
        $mailer->FromName = $this->fromName;

        $mailer->AddReplyTo($this->fromEmail);
        $mailer->AddAddress($this->emailAddressTo);

        $mailer->Subject = $this->title;
        $mailer->Body = $this->msg;

        if ($mailer->Send()) {
            return true;
        }

        return false;
    }


}